#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t in = fork();
    if (in == 0)
    {
        int count = 5;
        while (count--)
        {
            printf("这是一个子进程：PID: %d PPID:%d\n", getpid(), getppid());
            sleep(1);
        }
        exit(1);
    }
    else
    {
        printf("这是一个父进程：PID: %d PPID:%d\n", getpid(), getppid());
        sleep(8);
        printf("开始等待子进程\n");
        pid_t child1 = waitpid(-1,NULL,0);
        printf("等待结束,等待的子进程pid为:%d\n",child1);
    }
    sleep(3);
    return 0;
}
